//
//  PedometerViewController.m
//  BaChat
//
//  Created by dllo on 16/6/14.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "PedometerViewController.h"
#import "YNPedometerManager.h"
@interface PedometerViewController ()

@property (nonatomic, retain) UILabel *stepsLabel;
@property (nonatomic, retain) UILabel *distanceLabel;
@property (nonatomic, retain) UILabel *cadenceLabel;






@end

@implementation PedometerViewController
-(void)dealloc
{
    [_stepsLabel release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = RGBAColor(30, 5, 50);
    self.title = @"运 动";
//    self.stepsLabel = [[UILabel alloc]
//                       initWithFrame:CGRectMake(20, 150,
//                                                [UIScreen mainScreen].bounds.size.width - 40,
//                                                200)];
//    _stepsLabel.numberOfLines = 6;
//    _stepsLabel.backgroundColor = [UIColor redColor];
//    _stepsLabel.textColor = [UIColor whiteColor];
//    [self.view addSubview:_stepsLabel];
    
    self.stepsLabel = [[UILabel alloc] initWithFrame:CGRectMake(ROOTWIDTH / 5, 100, ROOTWIDTH / 2, ROOTHEIGHT / 3)];
    self.stepsLabel.font = [UIFont systemFontOfSize:30];
    self.stepsLabel.font = [UIFont fontWithName:@"今日步数" size:10];
    self.stepsLabel.textColor = [UIColor greenColor];
    self.stepsLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.stepsLabel];
    
    self.distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, ROOTHEIGHT - 150, ROOTWIDTH / 3 , 100)];
    self.distanceLabel.font = [UIFont systemFontOfSize:20];
    self.distanceLabel.textColor = [UIColor whiteColor];
    self.distanceLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.distanceLabel];
    
    self.cadenceLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.distanceLabel.frame.size.width + 50, self.distanceLabel.frame.origin.x, ROOTWIDTH / 3, 100)];
    self.cadenceLabel.font = [UIFont systemFontOfSize:20];
    self.cadenceLabel.textColor = [UIColor whiteColor];
    self.cadenceLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.cadenceLabel];

    
    
    
    
    
    __block PedometerViewController *weakSelf = self;
  //  __weak PedometerViewController *weakSelf = self;
  
    if ([YNPedometerManager isStepCountingAvailable]) {
        [[YNPedometerManager shared]
         startPedometerUpdatesTodayWithHandler:^(YNPedometerData *pedometerData,
                                                 NSError *error) {
             if (!error) {
                weakSelf.stepsLabel.text = [NSString stringWithFormat:@" 今日步数:%@\n",pedometerData.numberOfSteps];
                 
                 NSString *string = [NSString stringWithFormat:@"%@",pedometerData.distance];
                 
                 weakSelf.distanceLabel.text = [[string componentsSeparatedByString:@"."]lastObject];
                 
                 weakSelf.cadenceLabel.text = [NSString stringWithFormat:@"活跃度%@",pedometerData.currentCadence];
             }
         }];
    } else {
        
        
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"此设备仅支持iPhone5s及以上设备!" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alert animated:YES completion:nil];
        
       
    }

    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
